package com.oly.cms.general.controller.api;

import com.oly.cms.general.model.po.WebMenu;
import com.oly.cms.general.service.cache.WebMenuCacheService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/api/menu")
public class MenuApiController extends BaseController {

  @Autowired
  private WebMenuCacheService menuService;

  /**
   * 不涉及分页（树形菜单）
   * 
   * @param id
   * @return
   */
  @GetMapping("/tree/{id}")
  public AjaxResult getMenuTreeById(@PathVariable("id") Long id) {
    return AjaxResult.success(menuService.listWebMenusTreeById(id));
  }

  /**
   * 通过id获取导航树
   * 
   * @param columnId
   * @return
   */
  @GetMapping("/get/{columnId}")
  public AjaxResult getWebMenuId(@PathVariable("columnId") Long columnId) {
    return AjaxResult.success(menuService.getWebMenuById(columnId));
  }

  /**
   * 通过Id获取导航列表
   * 
   * @param columnId
   * @return
   */
  @GetMapping("/list/{columnId}")
  public AjaxResult listWebMenuById(@PathVariable("columnId") Long columnId) {
    return AjaxResult.success(menuService.listWebMenusById(columnId));
  }

  /**
   * 综合查询
   * 
   * @param webMenu
   * @return
   */
  @GetMapping("/list")
  public AjaxResult listWebMenu(WebMenu webMenu) {
    return AjaxResult.success(menuService.listWebMenus(webMenu));
  }

}
